package com.example.vp;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    VideoView videoView;
    MediaController mediaController;
    TextView text;
    EditText ed;
    Button btn;
    String s;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView=findViewById(R.id.video_view);

        text = findViewById(R.id.text);
        ed = findViewById(R.id.Ed);
        btn = findViewById(R.id.btn);

        mediaController=new MediaController(this);

        btn.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("WrongConstant")
            @Override
            public void onClick(View v) {
                s="/sdcard/Android/data/com.example.vp/file/"+ed.getText().toString()+".MP4";
                text.setText(s);
                File video = new File(s);
                if(video.exists())
                {
                    Toast.makeText(getApplicationContext(),"文件存在，点击视频处进行播放",50000).show();
                    videoView.setVideoPath(video.getAbsolutePath());
                    videoView.setMediaController(mediaController);
                    mediaController.setMediaPlayer(videoView);
                    videoView.requestFocus();
                }
                else{
                    Toast.makeText(getApplicationContext(),"视频播放失败，文件不存在",50000).show();
                }
            }

        });


}}
